package com.hs.controller;

import com.github.pagehelper.PageInfo;
import com.hs.entity.PsyAss;
import com.hs.service.PsyAssService;
import com.hs.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("PsyAss")
public class PsyAssController {
    @Autowired
    private PsyAssService psyAssService;
    @PostMapping
    public R addPsyAss(@RequestBody PsyAss psyAss){
        int i = psyAssService.addPsyAss(psyAss);
        if(i>0){
            return R.ok();
        }else{
            return R.fail("增加失败");
        }
    }
    @DeleteMapping("{id}")
    public R deletePsyAss(@PathVariable("id") int id){
        int i = psyAssService.deletePsyAss(id);
        if(i>0){
            return R.ok();
        }else{
            return R.fail("删除失败");
        }
    }
    @PutMapping
    public R updatePsyAss(@RequestBody PsyAss psyAss){
        int i = psyAssService.updatePsyAss(psyAss);
        if(i>0){
            return R.ok();
        }else{
            return R.fail("修改失败");
        }
    }
    @GetMapping("{id}")
    public R getPsyAssById(@PathVariable("id") int id){
        PsyAss psyAss = psyAssService.getpsyassById(id);
        if (psyAss!=null){
            return R.ok(psyAss);
        }
        return R.error("错误");
    }
    @GetMapping("page")
    public R getPsyAssByPage(PsyAss psyAss,
                             @RequestParam(required = false,defaultValue = "1") int pageNum,
                             @RequestParam(required = false,defaultValue = "2") int pageSize){
        PageInfo<PsyAss> PsyAssByPage =psyAssService.getpsyassByPage(psyAss,pageNum,pageSize);
        return R.ok(PsyAssByPage);
    }
    @GetMapping
    public R getpsyasslist(PsyAss psyAss){
        PageInfo<PsyAss> getpayasslist = psyAssService.getpayasslist(psyAss);
        return R.ok(getpayasslist);
    }
}
